(function(Global /*, context */) {

    function AddBot(){
        Game.AutoAssignPlayersToTeams();
        GameEvents.SendCustomGameEventToServer("add_bot", {});
    }

    function GetPlayerCount(){
        var count = 0;
        for (var i=0; i<=7; i++){
            var playerInfo = Game.GetPlayerInfo(i);
            if (playerInfo){
                count++;
            }
        }
        return count;
    }

    function OnUpdateBotCount(data){
        $("#BotCount").text = data.count;
        var connectedPlayerCount = GetPlayerCount();
        if(connectedPlayerCount != Game.GetAllPlayerIDs().length){
            $("#AddBotBtn").style.visibility = "collapse";
        } else {
            var localPlayer = Game.GetLocalPlayerInfo();
            if(localPlayer){
                if(localPlayer.player_has_host_privileges && connectedPlayerCount < 8){
                    $("#AddBotBtn").style.visibility = "visible";
                } else{
                    $("#AddBotBtn").style.visibility = "collapse";
                }
            }
        }
    }

    $("#AddBotBtn").SetPanelEvent("onactivate", AddBot);

    if(Game.GetAllPlayerIDs().length!==Game.GetAllTeamIDs().length){
        $("#Setting").style.visibility="visible"
    }

    GameEvents.Subscribe("update_bot", OnUpdateBotCount);



})(GameUI.CustomUIConfig(), this);